package com.ruoyi.application.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.zhuangtai.domain.AlgsType;
import com.ruoyi.zhuangtai.service.IAlgsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.application.domain.AlgsAnimalApplication;
import com.ruoyi.application.service.IAlgsAnimalApplicationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 动物申请Controller
 * 
 * @author ruoyi
 * @date 2023-03-17
 */
@RestController
@RequestMapping("/application")
public class AlgsAnimalApplicationController extends BaseController
{
    @Autowired
    private IAlgsAnimalApplicationService algsAnimalApplicationService;
    @Resource
    private IAlgsTypeService iAlgsTypeService;

    /**
     * 查询动物申请列表
     */
//    @RequiresPermissions("application:application:list")
    @GetMapping("/list")
    public TableDataInfo list(AlgsAnimalApplication algsAnimalApplication)
    {
        startPage();
        List<AlgsAnimalApplication> list = algsAnimalApplicationService.selectAlgsAnimalApplicationList(algsAnimalApplication);
        return getDataTable(list);
    }

    /**
     * 导出动物申请列表
     */
//    @RequiresPermissions("application:application:export")
    @Log(title = "动物申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsAnimalApplication algsAnimalApplication)
    {
        List<AlgsAnimalApplication> list = algsAnimalApplicationService.selectAlgsAnimalApplicationList(algsAnimalApplication);
        ExcelUtil<AlgsAnimalApplication> util = new ExcelUtil<AlgsAnimalApplication>(AlgsAnimalApplication.class);
        util.exportExcel(response, list, "动物申请数据");
    }

    /**
     * 获取动物申请详细信息
     */
//    @RequiresPermissions("application:application:query")
    @GetMapping(value = "/{animalApplicationId}")
    public AjaxResult getInfo(@PathVariable("animalApplicationId") Long animalApplicationId)
    {
        return success(algsAnimalApplicationService.selectAlgsAnimalApplicationByAnimalApplicationId(animalApplicationId));
    }

    /**
     * 新增动物申请
     */
//    @RequiresPermissions("application:application:add")
    @Log(title = "动物申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgsAnimalApplication algsAnimalApplication)
    {
//        AlgsType algsType = new AlgsType();
//        Long aLong = Long.valueOf(106);
//        algsType.setTypeId(aLong);
//        algsType.setTypeDesc("已提交");
//        algsType.setTypeMsg("动物申请");
//        iAlgsTypeService.insertAlgsType(algsType);

        return toAjax(algsAnimalApplicationService.insertAlgsAnimalApplication(algsAnimalApplication));
    }

    /**
     * 修改动物申请
     */
//    @RequiresPermissions("application:application:edit")
    @Log(title = "动物申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgsAnimalApplication algsAnimalApplication)
    {
        return toAjax(algsAnimalApplicationService.updateAlgsAnimalApplication(algsAnimalApplication));
    }

    /**
     * 删除动物申请
     */
//    @RequiresPermissions("application:application:remove")
    @Log(title = "动物申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{animalApplicationIds}")
    public AjaxResult remove(@PathVariable Long[] animalApplicationIds)
    {
        return toAjax(algsAnimalApplicationService.deleteAlgsAnimalApplicationByAnimalApplicationIds(animalApplicationIds));
    }
}
